package edu.sctu.zhangwang.month201506.day20150628.list_hash;


import com.alibaba.fastjson.JSONObject;
import edu.sctu.zhangwang.month201506.day20150628.test_day0628.json_data.JsonApp;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by Administrator on 2015/6/28.
 */
public class OneTest {
    public URL url;
    public String getData(){
        int sum = 0;
        int count=0;
        String str="";
        byte[] bytes = new byte[1024];
        try {
            url = new URL("http://api.ii.com.cn/goods/apprec");
            try {
                URLConnection urlConnection = url.openConnection();
                InputStream inputStream = urlConnection.getInputStream();

                while ((count = inputStream.read(bytes))!=-1){
                    sum += count;
                    str += new String(bytes,0,count,"utf-8");
                    System.out.println();
                }
                System.out.println(str);
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return str;
    }

    public void Json(){

        JSONObject jsonObject = new JSONObject();
        JsonApp jsonApp = jsonObject.parseObject(getData(), JsonApp.class);
        System.out.println(jsonApp.message);
    }
    public static void main(String[] args) {
        OneTest oneTest = new OneTest();
        oneTest.getData();
        oneTest.Json();
    }
}
